<?php

namespace App\Observers;

use App\Models\Borker;
use App\server\RedisServer;
class BorkerObserver
{
    /**
     * Handle the Borker "created" event.
     *
     * @param  \App\Models\Borker  $borker
     * @return void
     */
    public function created(Borker $borker)
    {
        //
        $redis=RedisServer::createRedisObject();
        $redis->select(7);
        $borkerdata=$borker->toArray();
        $redis->hSetone($borkerdata);
    }

    /**
     * Handle the Borker "updated" event.
     *
     * @param  \App\Models\Borker  $borker
     * @return void
     */
    public function updated(Borker $borker)
    {
        //
        $data=$borker->toArray();
        $redis=RedisServer::createRedisObject();
        $redis->select(7);
        foreach ($data as $key => $value){
            $redis->hset($data['id'],$key,$value);
        }
    }

    /**
     * Handle the Borker "deleted" event.
     *
     * @param  \App\Models\Borker  $borker
     * @return void
     */
    public function deleted(Borker $borker)
    {
        //
    }

    /**
     * Handle the Borker "restored" event.
     *
     * @param  \App\Models\Borker  $borker
     * @return void
     */
    public function restored(Borker $borker)
    {
        //
    }

    /**
     * Handle the Borker "force deleted" event.
     *
     * @param  \App\Models\Borker  $borker
     * @return void
     */
    public function forceDeleted(Borker $borker)
    {
        //
    }
}
